/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Supermarket;

import CustomerGUIs.ChangePasswordForm;
import CustomerGUIs.ListOfChecksForm;
import CustomerGUIs.NewCustomerForm;
import Model.InternalDBManager;
import PurchaseGUIs.PurchaseForm;
import javax.persistence.EntityManager;
import javax.swing.ImageIcon;

/**
 *
 * @author Manolis
 */
public class MainForm2 extends javax.swing.JFrame {
    private LoginUser loginUser;
    private EntityManager em ;

    /**
     * Creates new form CustomersMain
     */
      public MainForm2(LoginUser loginUser) {
        this.em = InternalDBManager.getEm();
         if (!em.getTransaction().isActive()){
                em.getTransaction().begin();
            }
        this.loginUser = loginUser;
        this.setIconImage(new
                ImageIcon(getClass().getResource("..\\Images\\cart.png")).getImage()); 
        initComponents();
        }
      
        public MainForm2() {
        this.setIconImage(new
                ImageIcon(getClass().getResource("..\\Images\\cart.png")).getImage()); 
        initComponents();
        }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        CustomersPanel = new javax.swing.JPanel();
        CustomersDetailsButton = new javax.swing.JButton();
        CustomersChangePasswordButton = new javax.swing.JButton();
        CustomersChecksButton = new javax.swing.JButton();
        CustomersBuysButton = new javax.swing.JButton();
        Thes2Button = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        LoginUserLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(1024, 768));

        CustomersPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        CustomersDetailsButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CustomersDetailsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/customers_50.png"))); // NOI18N
        CustomersDetailsButton.setText("Προφίλ Πελάτη");
        CustomersDetailsButton.setToolTipText("");
        CustomersDetailsButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        CustomersDetailsButton.setFocusable(false);
        CustomersDetailsButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        CustomersDetailsButton.setIconTextGap(1);
        CustomersDetailsButton.setPreferredSize(new java.awt.Dimension(70, 30));
        CustomersDetailsButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        CustomersDetailsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CustomersDetailsButtonActionPerformed(evt);
            }
        });

        CustomersChangePasswordButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CustomersChangePasswordButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/padlock.png"))); // NOI18N
        CustomersChangePasswordButton.setText("Αλλαγή Κωδικού");
        CustomersChangePasswordButton.setToolTipText("");
        CustomersChangePasswordButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        CustomersChangePasswordButton.setFocusable(false);
        CustomersChangePasswordButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        CustomersChangePasswordButton.setIconTextGap(1);
        CustomersChangePasswordButton.setPreferredSize(new java.awt.Dimension(70, 30));
        CustomersChangePasswordButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        CustomersChangePasswordButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CustomersChangePasswordButtonActionPerformed(evt);
            }
        });

        CustomersChecksButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CustomersChecksButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/checks_50.png"))); // NOI18N
        CustomersChecksButton.setText("Επιταγές");
        CustomersChecksButton.setToolTipText("");
        CustomersChecksButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        CustomersChecksButton.setFocusable(false);
        CustomersChecksButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        CustomersChecksButton.setIconTextGap(1);
        CustomersChecksButton.setPreferredSize(new java.awt.Dimension(70, 30));
        CustomersChecksButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        CustomersChecksButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CustomersChecksButtonActionPerformed(evt);
            }
        });

        CustomersBuysButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CustomersBuysButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Shopping cart_50.png"))); // NOI18N
        CustomersBuysButton.setText("Αγορές");
        CustomersBuysButton.setToolTipText("");
        CustomersBuysButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        CustomersBuysButton.setFocusable(false);
        CustomersBuysButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        CustomersBuysButton.setIconTextGap(1);
        CustomersBuysButton.setPreferredSize(new java.awt.Dimension(70, 30));
        CustomersBuysButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        CustomersBuysButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CustomersBuysButtonActionPerformed(evt);
            }
        });

        Thes2Button.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        Thes2Button.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/THES2_75.jpg"))); // NOI18N
        Thes2Button.setToolTipText("");
        Thes2Button.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        Thes2Button.setFocusable(false);
        Thes2Button.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        Thes2Button.setIconTextGap(1);
        Thes2Button.setPreferredSize(new java.awt.Dimension(70, 30));
        Thes2Button.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        Thes2Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Thes2ButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout CustomersPanelLayout = new javax.swing.GroupLayout(CustomersPanel);
        CustomersPanel.setLayout(CustomersPanelLayout);
        CustomersPanelLayout.setHorizontalGroup(
            CustomersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CustomersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(CustomersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(CustomersDetailsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CustomersChangePasswordButton, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CustomersChecksButton, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CustomersBuysButton, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Thes2Button, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        CustomersPanelLayout.setVerticalGroup(
            CustomersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CustomersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(CustomersDetailsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(CustomersChangePasswordButton, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(CustomersChecksButton, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(CustomersBuysButton, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 167, Short.MAX_VALUE)
                .addComponent(Thes2Button, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLabel1.setFont(new java.awt.Font("Arial Black", 1, 36)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Karotsi_515.png"))); // NOI18N
        jLabel1.setText("Super Market V1.0");
        jLabel1.setToolTipText("");
        jLabel1.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        LoginUserLabel.setText(" ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(LoginUserLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(192, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(0, 13, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGap(0, 13, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(0, 686, Short.MAX_VALUE)
                .addComponent(LoginUserLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(0, 89, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGap(0, 89, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(CustomersPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(CustomersPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CustomersDetailsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CustomersDetailsButtonActionPerformed

        NewCustomerForm customerProfileForm = new NewCustomerForm(this, true, loginUser );
        customerProfileForm.setVisible(true);

    }//GEN-LAST:event_CustomersDetailsButtonActionPerformed

    private void CustomersChangePasswordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CustomersChangePasswordButtonActionPerformed
      ChangePasswordForm changeCustomerForm = new ChangePasswordForm(loginUser); 
      changeCustomerForm.setVisible(true);
    }//GEN-LAST:event_CustomersChangePasswordButtonActionPerformed

    private void CustomersChecksButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CustomersChecksButtonActionPerformed
       ListOfChecksForm listOfChecksForm = new ListOfChecksForm(loginUser);
       listOfChecksForm.setVisible(true);
       
    }//GEN-LAST:event_CustomersChecksButtonActionPerformed

    private void CustomersBuysButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CustomersBuysButtonActionPerformed
       PurchaseForm purchaseForm = new PurchaseForm(loginUser);
       purchaseForm.setVisible(true); 
       
    }//GEN-LAST:event_CustomersBuysButtonActionPerformed

    private void Thes2ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Thes2ButtonActionPerformed
        AboutForm aboutForm = new AboutForm(this, true);
        aboutForm.setVisible(true);
    }//GEN-LAST:event_Thes2ButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainForm2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainForm2().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CustomersBuysButton;
    private javax.swing.JButton CustomersChangePasswordButton;
    private javax.swing.JButton CustomersChecksButton;
    private javax.swing.JButton CustomersDetailsButton;
    private javax.swing.JPanel CustomersPanel;
    private javax.swing.JLabel LoginUserLabel;
    private javax.swing.JButton Thes2Button;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables

}
